module Actor;
import std.conv;
import CheckRoll;
import ToHit;

abstract class Actor {
	protected string s_type;
	@property string type() {
		return s_type;
	}
	protected ubyte ub_wounds;
	@property ubyte wounds() {
		return ub_wounds;
	}
	protected ubyte ub_woundsLeft;
	@property ubyte woundsLeft() {
		return ub_woundsLeft;
	}
	protected ubyte ub_move;
	@property ubyte move() {
		return ub_move;
	}
	protected ubyte ub_weaponSkill;
	@property ubyte weaponSkill() {
		return ub_weaponSkill;
	}
	protected ubyte ub_ballisticSkill;
	@property ubyte ballisticSkill() {
		return ub_ballisticSkill;
	}
	protected ubyte ub_strength;
	@property ubyte strength() {
		return ub_strength;
	}
	protected ubyte ub_toughness;
	@property ubyte toughness() {
		return ub_toughness;
	}
	protected ubyte ub_armour;
	@property ubyte armour() {
		return ub_armour;
	}
	protected ubyte ub_initiative;
	@property ubyte initiative() {
		return ub_initiative;
	}
	protected ubyte ub_attacks;
	@property ubyte attacks() {
		return ub_attacks;
	}
	this(string ty, ubyte w, ubyte m, ubyte ws, ubyte bs, ubyte s, ubyte t, ubyte ar, ubyte i, ubyte a) {
		s_type = ty;
		ub_wounds = w;
		ub_woundsLeft = w;
		ub_move = m;
		ub_weaponSkill = ws;
		ub_ballisticSkill = bs;
		ub_strength = s;
		ub_toughness = t;
		ub_armour = ar;
		ub_initiative = i;
		ub_attacks = a;
	}
	public ubyte attack(Actor defender) {
		if(!toHitRoll(defender))
			return 0;
		return defender.hit(damageRoll());
	}
	public bool toHitRoll(Actor defender) {
		ToHit chart = new ToHit();
		CheckRoll hit = new CheckRoll(chart.get(ub_weaponSkill, defender.weaponSkill));
		return hit.check();
	}
	public ubyte damageRoll() {
		Dice d6 = new Dice();
		return to!(ubyte)(d6.roll() + ub_strength);
	}
	public ubyte hit(ubyte x) {
		ubyte modifier = to!(ubyte)(ub_toughness + ub_armour);
		if(modifier >= x)
			return 0;
		ubyte damage = to!(ubyte)(x - modifier);
		if(damage > ub_woundsLeft)
			ub_woundsLeft = 0;
		else
			ub_woundsLeft -= damage;
		return damage;
	}
}

